let express = require("express")();
let expressStatic = require("express-static");
let mysql = require("mysql");
const { response } = require("express");
const port = 83;

let sql = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "123456",
    database: "test"
})

sql.connect();

// 列表页
express.get("/getList", (request, response) => {
    sql.query(`select id,image,heading,label from chuanyue`, (error, data) => {
        response.send(data)
    })
})

// 详情页
express.get("/getnews", (request, response) => {
    let id = request.query.id
    sql.query(`select * from chuanyue where id = ${id}`, (error, data) => {
        if (error) {
            response.send("error");
            console.log(error);
        } else {
            response.send(data[0])
        }
    })
})


express.use(expressStatic(__dirname + "/static"));
console.log(`server is running at ${port}`);
express.listen(port)